import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QMdiArea,QMdiSubWindow,QLabel

class MidArea(QMainWindow):
    def __init__(self):

        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle('demo')
        self.setGeometry(300,300,300,200)

        bar=self.menuBar()
        file=bar.addMenu('File')
        file.addAction('new')
        file.addAction('cascade')
        file.addAction('tile')
        file.triggered.connect(self.showWindow)


        #------定义QMdiArea,用来放置子窗口------
        self.area=QMdiArea()
        self.setCentralWidget(self.area)


    def showWindow(self,data):
        text=data.text()
        if text=='new':

            #创建一个新的窗口
            subwindow=QMdiSubWindow()
            #为子窗口添加组件
            subwindow.setWindowTitle('这是QMdiSubWindow')
            subwindow.setWidget(QLabel('hello'))
            #将字窗口添加到区域QmdiArea
            self.area.addSubWindow(subwindow)
            #子窗口显示
            subwindow.show()
        if text=='cascade':
            #设置窗口级联显示
            self.area.cascadeSubWindows()

        if text=='tile':
            #设置窗口平铺显示
            self.area.tileSubWindows()




if __name__=='__main__':
    app=QApplication(sys.argv)

    demo=MidArea()
    demo.show()
    sys.exit(app.exec_())
